package CountVertex;

import java.io.IOException;
import java.util.Hashtable;
import java.util.Iterator;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.MapReduceBase;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reducer;
import org.apache.hadoop.mapred.Reporter;

public class CountVertexReducer extends MapReduceBase implements
		Reducer<Text, LongWritable, Text, LongWritable> {
	Hashtable<LongWritable, Boolean> ht = new Hashtable<LongWritable, Boolean>();

	@Override
	public void reduce(Text key, Iterator<LongWritable> values,
			OutputCollector<Text, LongWritable> output, Reporter reporter)
			throws IOException {

		int sum = 0;
		while (values.hasNext()) {
			LongWritable current = values.next();
			if (!ht.contains(current)) {
				ht.put(current, true);
			}
		}
		output.collect(new Text("Vertex Number: "), new LongWritable(ht.size()));

	}
}
